package com.lz.football.module.activity.topupfeedback
{
	import com.common.utils.Reflection;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.message.http.JsClient;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.activity.IActivity;
	
	import common.BaseView.BaseView;
	import common.BaseView.GoodItem;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.text.TextField;
	
	import mx.effects.Move;

	/**
	 * 充值回馈活动 
	 * @author Administrator
	 * 
	 */	
	public class TopupfeedbackView extends BaseView implements IActivity
	{
		
		
		private var _itemVec:Vector.<GoodItem>;
		/**
		 *进度 
		 */
		private var pro:MovieClip;
		/**
		 *充值金额 
		 */
		private var topUP:TextField;
		/**
		 * 
		 */
		private var topUpBtn:SimpleButton;
		
		private var _obj:Object;
		
		/**
		 *时间 
		 */
		private var timeTxt:TextField;
		public function TopupfeedbackView()
		{
			super();
		}
		/**
		 * 
		 * @param view
		 * 
		 */
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.res.activity.topupfeedbackView");
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.feedbackBg;
			isDrag = true;
			isCloseBtn = true;
			
			moveClose(symbolSkin.width - 28,25);
			_viewHeight = symbolSkin.height;
			_viewWidth = symbolSkin.width;
			timeTxt = symbolSkin.timeTxt;
			pro = symbolSkin.pro;
			topUpBtn = symbolSkin.topUpBtn;
			pro.gotoAndStop(1);
			topUP = symbolSkin.topUP;
			onResizeHandler();
			addEvtListener();
			initItem();
			var xml:XML = ResourceManager.instance.getResource(ResourceConst.ACTIVITYTIME_XML);
			
			
			timeTxt.text = "活动时间：" + xml.Topupfeedback + "截止";;
		}
		private function initItem():void
		{
			var arr:Array = AppData.getInstance().activityDatemanager.Topupfeedback;
			var len:int = arr.length;
			_itemVec = new Vector.<GoodItem>();
			var item:GoodItem;
			for(var i:int = 0;i < len;i++)
			{
				item = new GoodItem();
				item.initUI();
				item.data = AppData.getInstance().goodsManager.getGoodsByTypeAndId(arr[i][1],arr[i][0]);;
				this.addChild(item);
				item.x = 61 + (125) * i;
				item.y = 145;
				_itemVec.push(item);
			}
			_itemVec[5].x = 238;
			_itemVec[5].y = 258;
			_itemVec[6].x = 519;
			_itemVec[6].y = 258;
		}
		override public function addEvtListener():void
		{
			super.addEvtListener();
			for(var i:int = 1;i <= 7;i++)
			{
				symbolSkin["btn_" + i].addEventListener(MouseEvent.CLICK,onClickHandler);
			}
			topUpBtn.addEventListener(MouseEvent.CLICK,ontopUpHandler);
		}
		
		protected function ontopUpHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			JsClient.recharge();
		}
		private function onClickHandler(event:MouseEvent):void
		{
			var id:int = 0;
			switch(event.currentTarget)
			{
				case symbolSkin.btn_1:
					id = 1;
					break;
				case symbolSkin.btn_2:
					id = 2;
					break;
				case symbolSkin.btn_3:
					id = 3;
					break;
				case symbolSkin.btn_4:
					id = 4;
					break;
				case symbolSkin.btn_5:
					id = 5;
					break;
				case symbolSkin.btn_6:
					id= 6;
					break;
				case symbolSkin.btn_7:
					id = 7
					break;
				
			}
			this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_TOPUPFEEDBACK_AWARD,{id:id}));
		}
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ModuleEvent(ModuleEvent.REMOVE_MODULE));
		}
		/**
		 *活跃度信息 
		 * @param $obj
		 * 
		 */
		public function baseinformation($obj:Object):void
		{
			var cash:int = $obj.cashpoint;
			topUP.text = "" + cash + "/" + 200000;
			cash = cash >200000?200000:cash;
			if(cash <=0)cash = 0;
			var p:int = Math.ceil((cash/ 200000) * 100) ;
			pro.gotoAndStop(p);
			_obj = $obj;
			for(var i:int = 1;i <= 7;i++)
			{
				if(_obj["status"+ i] > 0)
				{
					symbolSkin["btn_" + i].mouseEnabled =true;
					symbolSkin["btn_" + i].filters = null;
				}else
				{
					symbolSkin["btn_" + i].mouseEnabled =false;
					symbolSkin["btn_" + i].filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0,
						0.3086, 0.6094, 0.082, 0, 0,
						0.3086, 0.6094, 0.082, 0, 0,
						0,0,0,1,0,])];
				}
			}
			
			
			
			if(_obj["status"+ 6] == 2)
			{
				symbolSkin["btn_" + 6].mouseEnabled =false;
				symbolSkin["btn_" + 6].filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0,0,0,1,0,])];
			}
			if(_obj["status"+ 7] == 2)
			{
				symbolSkin["btn_" + 7].mouseEnabled =false;
				symbolSkin["btn_" + 7].filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0,0,0,1,0,])];
			}
			
				
		}
		/**
		 *领取奖励返回 
		 * 
		 */
		public function award($obj:Object):void
		{
			if(!$obj.status)return;
			var id:int = $obj.id;
			_obj["status" + id] -= 1;
			baseinformation(_obj);
		}
		override public function removeEvtListener():void
		{
			super.removeEvtListener();
			for(var i:int = 1;i <= 7;i++)
			{
				symbolSkin["btn_" + i].removeEventListener(MouseEvent.CLICK,onClickHandler);
			}
			topUpBtn.removeEventListener(MouseEvent.CLICK,ontopUpHandler);
		}
		override public function destroyView():void
		{
			removeEvtListener();
			super.destroyView();
		}
	}
}